package com.david.xlib.widget;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by david on 16/12/23.
 * 1，scrollable false 禁止左右滑屏
 * 2，setCurrentItem(item, false) 去掉左右滑动动画
 */
public class XViewPager extends ViewPager {
    private boolean scrollable = false;

    public XViewPager(Context context) {
        super(context);
    }

    public XViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setScrollable(boolean isScroll) {
        this.scrollable = isScroll;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return scrollable ? super.onInterceptTouchEvent(ev) : false;
    }

    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {
        super.setCurrentItem(item, smoothScroll);
    }

    @Override
    public void setCurrentItem(int item) {
        super.setCurrentItem(item, false);
    }
}
